//牛顿法求平方根
function sqrt(x){
    return sqrtGuess(x,1)
}
function sqrtGuess(x,guess){
    if(isGoodEnough(x,guess)){
        return guess
    }
    return sqrtGuess(x,average(x,guess))
}

function average(x,guess){
    return (guess+x/guess)/2
}
function isGoodEnough(x,guess){
    const delta=0.001
    return abs(guess**2-x)<delta
}
function abs(x){
    if(x>0){return x}
    return -x
}

const x=0.01

console.log(sqrt(x))

//计算换零钱方式，零钱种类1元、2元、5元、10元

// function changeCount(amount) {
//     const coins=[1,2,5,10];
//     const result=[];      
//     for(let i=0;i<coins.length;i+=1){
//         for(let j=coins[i];j<=amount;j+=1){
//             result[0]=1;
//             result[j]=result[j]+result[j-coins[i]]
//         }
//         return result[amount]
//     }
// }
// const amount=2
// console.log(changeCount(amount))

function changeCount(amount){

    function ccIter(amount,n=0){
        const coins=[1,2,5,10];
        if(amount==0)return 1;
        if(amount<0||n>=coins.length) return 0;
        return ccIter(amount,n+1)+ccIter(amount-coins[n],n);
    }
    return ccIter(amount)
}
const amount=5
console.log(changeCount(amount))